using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GameManager : MonoBehaviour
{
    public static GameManager instance;
    private int npcsCount;

    private UI ui;

    private float time=60f;
    /// <summary>
    /// Awake is called when the script instance is being loaded.
    /// </summary>
    void Awake()
    {
        if (instance == null)
        {
            instance = this;
            DontDestroyOnLoad(gameObject);
        }
        else
        {
            Destroy(gameObject);
        }
    }

    // Start is called before the first frame update
    void Start()
    {
        npcsCount=FindObjectsOfType<NPC>().Length;
        ui=FindObjectOfType<UI>();
    }
    public void DestroyNPC()
    {
        npcsCount--;
        if(npcsCount==0)
        {
            ui.ShowWinPanel();
            Time.timeScale=0;
        }

    }

    // Update is called once per frame
    void Update()
    {
        ui.UpdateTime(time);
        time-=Time.deltaTime;
        if(time<=0)
        {
            ui.ShowGameOverPanel();
            Time.timeScale=0;
        }
    }
}
